package com.example.demo.repository;

import com.example.demo.entity.Status;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

/**
 * Created by ajinlong on 2021/7/29.
 */

@Repository
public interface StatusRepository extends CrudRepository<Status,Integer>{
    // 查找某作者的博文
    List<Status> findByAuthor(String author);

    // 查找点赞数大于某值的博文
    List<Status> findByLikesGreaterThan(int likes);

    // 查找包含某关键字的博文
    List<Status> findByContentContainingIgnoreCase(String keyword);

    // 查找某作者在某时间前发布的博文，并按发布时间升序排序
    List<Status> findByAuthorAndCreateTimeBeforeOrderByCreateTime(String author, Timestamp timestamp);

    // 查找某月份发布的博文
    @Query("select s from Status s where month(s.createTime) = ?1")
    List<Status> findStatusInMonth(int month);

    // 删除某作者的博文
    @Transactional
    Long deleteByAuthor(String author);
}
